package jp.ne.hatena.d.digitalsoul.warikan.actions

import java.io._
import java.text._
import java.util._

import jp.ne.hatena.d.digitalsoul.warikan.contexts._
import jp.ne.hatena.d.digitalsoul.warikan.pages.forms._
import jp.ne.hatena.d.digitalsoul.warikan.pages.items._
import jp.ne.hatena.d.digitalsoul.warikan.repositories._

class PlanningAction extends Serializable {
	
	private val format = new SimpleDateFormat("yyyy/MM/dd")
		
	def createRoleList:List[String] = {
		val roles = new ArrayList[String]
		RoleRepository.forAll.foreach { role =>
			roles.add(role.name)
		}
		roles
	}
	
	def executePlanning(mainFormModel:PlanningMainForm, participantListItems:List[ParticipantListItem]) = {
		
		val planning:Planning = new Planning
		val date:Date = format.parse(mainFormModel.schedule)
		planning.setup(mainFormModel.partyName, date, mainFormModel.location)
			
		for(val i <- 0 until participantListItems.size) {
			val item = participantListItems.get(i)
			planning.addPerticipant(item.name, item.role)
		}
			
		planning.commit

	}

}